<?

	
require_once("fta.201003310000/fta.php");
fta_registerModules(
	array(
	"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
	"site/fta/config",
));		
	

/**
    [REDIRECT_ERROR_NOTES] => File does not exist: /var/users/gravitat/yakmoose.org.nz/htdocs/sdfwerwre
    [REDIRECT_REQUEST_METHOD] => GET
    [REDIRECT_SCRIPT_URI] => http://www.yakmoose.org.nz/sdfwerwre
    [REDIRECT_SCRIPT_URL] => /sdfwerwre
    [REDIRECT_STATUS] => 404
    [REDIRECT_URL] => /sdfwerwre
*/

	$statusMessages = array(
		200 =>	"OK",
		400 => "Bad Request",
		401 => "Unauthorised",
		403 => "Forbidden",
		404 => "Not Found",
		500 => "Internal Server Error",
		501 => "Not Implemented"
	);

	$fullErrorMessages=array(
		200 =>	"OK",	
		400 => "The request could not be understood by the server.",
		401 => "The request requires user authentication.",
		403 => "Access to the requested file is denied",
		404 => "The requested file was not found on the server. Please check that you have entered the URL correctly and try again.",
		500 => "The server encountered an unexpected condition which prevented it from fulfilling the request",
		501 => "The server does not support the functionality required to fulfill the request."
	);
	
	$errorMessageTitle = array (
		200 =>	"OK",	
		400 => "Bad Request",
		401 => "Unauthorised Access",
		403 => "Access Forbidden",
		404 => "File Not Found",
		500 => "Internal Server Error",
		501 => "Not Implemented"	
	);
	
	if (array_key_exists('REDIRECT_STATUS',$_SERVER))
		$status = $_SERVER['REDIRECT_STATUS'];
	else 
		$status= 404;
		
	$serverProtocol = $_SERVER['SERVER_PROTOCOL'];

	if ($status == 404 || $status == 200){
		$cmsDocument = new CmsDocument($db);	
		$cmsDocument->flush();	
		
		$cmsDocument->addDocumentType('pagebuilder');
		$cmsDocument->addConstraint('formid', '187');
		
		$cmsDocument->addConstraint('<<md.urlfragment>>',($_SERVER['REQUEST_URI']));
		$cmsDocument->setActiveDocuments();
		$cmsDocument->setPageSize(1);
		$cmsDocument->resetIterator();
		$documents= $cmsDocument->getAllDocuments();
		
		if ($documents && count($documents) == 1){
		

			$_GET['id']	 = $documents[0]->categorycode;
			
			
//		
//			now.. the page builder magical bootstrapp
//				


			$status=200;
			header( $serverProtocol ." ".  $status ." ".  $statusMessages[$status],true);

			include(CMS_SITE_HOME . 'pageBuilder/pageBuilder.php');
			die();
			
		} elseif(!is_null(extractStringWithKeyFromArray("id", $_REQUEST, null))){
			$id = extractStringWithKeyFromArray("id", $_REQUEST, null);
			$cmsDocument->flush();	
			$cmsDocument->addDocumentType('pagebuilder');
			$cmsDocument->addConstraint('formid', '187');
			$cmsDocument->addConstraint('categorycode',$id);
			$cmsDocument->setActiveDocuments();
			$cmsDocument->setPageSize(1);
			$cmsDocument->resetIterator();
			$documents= $cmsDocument->getAllDocuments();
			
			if ($documents && count($documents) == 1){
				
				$_GET['id']	 = $documents[0]->categorycode;
				
				$status=200;
				header( $serverProtocol ." ".  $status ." ".  $statusMessages[$status],true);

				include(CMS_SITE_HOME . 'pageBuilder/pageBuilder.php');
					
				die();
			} else {
				$status=404;
			}
			
		} else {
			
			//fail..
			
			//do a real 404 errorororororor
			$status=404;
		}		
	}	
	
//	
	
	if ($status != 200 ){
		header( $serverProtocol ." ".  $status ." ".  $statusMessages[$status],true);

	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?= $status ?> <?= $statusMessages[$status] ?></title>
<style type="text/css">
<!--
body {
	margin: 0;
	font: 12px "Trebuchet MS", Verdana, Arial, sans-serif;
	}
	
#container {
	margin: 0px auto 0px auto;
	width: 782px;
	background: url(/gravitate/404bg.gif) no-repeat;
	text-align: center;
	}
.right {
	padding: 30px 0px 0px 30px;
	border-left: 1px solid #e5e5e5;
	}
.left {
	padding: 30px 30px 0px 0px;
	}
h1 {
	margin: 0px 0px 15px 0px;
	font-size: 15px;
	color: #d54b00;
	}
a {
	color: #d54b00;

}
-->
</style>
</head>

<body>

<div id="container">

<table width="640" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td align="left" valign="top" class="left"><a href="http://www.gravitate.co.nz" target="_blank"><img
src="/gravitate/404logo.gif" alt="Gravitate" border="0" /></a></td>
    <td align="left" valign="top" class="right">
	
<h1><?= $errorMessageTitle[$status]  ?>!</h1>

<?= $fullErrorMessages[$status] ?>
<br />
<br />


Please check that you have entered the URL correctly and try again. If you believe that there has been an error please send an email containing the requested URL to  <a href="mailto:<?= $_SERVER['SERVER_ADMIN']?>"><?= $_SERVER['SERVER_ADMIN']?></a>.

	</td>
  </tr>
</table>


</div>
</body>
</html>
<pre>
</pre>
<?
}


//	myPrintR($_REQUEST,"Req");
//	myPrintR($_SERVER,"ser");
